<!DOCTYPE html>
<html lang="zh-CN">

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>商品管理</title>
	[#include "/admin/common/commons.html"]
	[#include "/tenant/common/site.html"]
	[#include "/tenant/default/product/componentAdd.html"]
	[#include "/tenant/default/product/componentList.html"]
	[#include "/tenant/default/product/componentUpdate.html"]
	[#include "/tenant/default/product/componentShow.html"]

	[@baseHead /]
	<script type="text/javascript"></script>
</head>

<body class="hold-transition skin-blue sidebar-mini">
	<!-- Site wrapper -->
	<div class="wrapper">

		<header class="main-header">
			<!-- Header Navbar: style can be found in header.less -->
			[#include "/admin/common/nav.html"]
		</header>

		<!-- =============================================== -->

		<!-- Left side column. contains the sidebar -->
		<aside class="main-sidebar">
			<!-- sidebar: style can be found in sidebar.less -->
			<section class="sidebar">
				[@user_panel /]
				<!-- search form -->
				[@sidebar_form /]
				<!-- /.search form -->
				<!-- sidebar menu: : style can be found in sidebar.less -->
				<ul class="sidebar-menu" data-widget="tree">
					<li class="header">主面板</li>
					[@menustag id=1]
					[#list list as item]
					[@menu item "1,125,127"]
					[/@menu]
					[/#list]
					[/@menustag]
				</ul>
			</section>
			<!-- /.sidebar -->
		</aside>

		<!-- =============================================== -->

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper" id="app" v-cloak>
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<!-- 导航 -->
				<div class="navigation">
					<i>首页</i> <span>商品管理</span>
				</div>
			</section>
			<!-- Main content -->
			<section class="content">
				<keep-alive>
					<router-view v-if="$route.meta.keepAlive">
					</router-view>
				</keep-alive>
				<router-view v-if="!$route.meta.keepAlive">
				</router-view>
				<!-- Default box -->
			</section>


			<!-- /.content -->
		</div>
		<!-- /.content-wrapper -->

		[#include "/admin/common/footer.html"]

		<!-- Control Sidebar -->
		[#include "/admin/common/aside.html"]

		<!-- /.control-sidebar -->
		<!-- Add the sidebar's background. This div must be placed
     immediately after the control sidebar -->
		<div class="control-sidebar-bg"></div>
	</div>
	<!-- ./wrapper -->
	[@baseScript /]
	[#include "/tenant/common/component.html" /]
	[@avatar /]
	[@ueConfig /]

	<script type="text/javascript">

		function descartes(list) {
			//parent上一级索引;count指针计数
			var point = {};

			var result = [];
			var pIndex = null;
			var tempCount = 0;
			var temp = [];

			//根据参数列生成指针对象
			for (var index in list) {
				if (typeof list[index] == 'object') {
					point[index] = { 'parent': pIndex, 'count': 0 }
					pIndex = index;
				}
			}

			//单维度数据结构直接返回
			if (pIndex == null) {
				return list;
			}

			//动态生成笛卡尔积
			while (true) {
				for (var index in list) {
					tempCount = point[index]['count'];
					temp.push(list[index][tempCount]);
				}

				//压入结果数组
				result.push(temp);
				temp = [];

				//检查指针最大值问题
				while (true) {
					if (point[index]['count'] + 1 >= list[index].length) {
						point[index]['count'] = 0;
						pIndex = point[index]['parent'];
						if (pIndex == null) {
							return result;
						}

						//赋值parent进行再次检查
						index = pIndex;
					}
					else {
						point[index]['count']++;
						break;
					}
				}
			}
		}
		var config = {};

		config.methods = {};

		[@configBasicVue /]

		config.methods.goBack = function () {
			this.$router.go(-1);
		}
		config.basicMethod = function () {
			var result = {};
			result.postData = config.methods.postData;
			result.postJsonData = config.methods.postJsonData;
			result.goBack = config.methods.goBack;
			return result;
		}

		config.methods.loadShopOptions = function () {
			var self = this;
			var param = {};
			param.sortMethod = "asc";
			param.sortField = "id";
			param.level = 1;
			param.size = 500;
			param.fetch = 0;
			$.post("${siteurl}tenantRest/shop/list.htm", param, function (result) {
				if (result.code == 0) {
					self.$store.commit('updateShopOptions', result.list);
				}
			});
		}

		config.methods.loadProductCatalogOptions = function () {
			var self = this;
			var param = {};
			param.sortMethod = "asc";
			param.sortField = "id";
			param.level = 1;
			param.size = 500;
			param.fetch = 1;
			$.post("${siteurl}tenantRest/productcatalog/list.htm", param, function (result) {
				if (result.code == 0) {
					self.$store.commit('updateProductCatalogOptions', result.list);
				}
			});
		}

		config.methods.loadProductGroupOptions = function () {
			var self = this;
			var param = {};
			param.sortMethod = "asc";
			param.sortField = "id";
			param.level = 1;
			param.size = 500;
			param.fetch = 0;
			$.post("${siteurl}tenantRest/productgroup/list.htm", param, function (result) {
				if (result.code == 0) {
					self.$store.commit('updateProductGroupOptions', result.list);
				}
			});
		}


	</script>



	[@productAddConfig /]
	[@productListConfig /]
	[@productShowConfig /]
	[@productUpdateConfig /]

	[@childProductConfig /]

	<script type="text/javascript">

		// 3. 创建 router 实例，然后传 `routes` 配置
		// 你还可以传别的配置参数, 不过先这么简单着吧。
		var appConfig = {};
		appConfig.el = "#app";


		const routes = [
			{
				path: '/view', name: "productShowView", component: productShowView, props: true, children: [
					{ path: "/view/index", name: "childProductShowView", component: childProductShowView },
					{ path: "/", component: childProductShowView }
				]
			},
			{ path: '/add', name: "productAddView", component: productAddView, props: true },
			{ path: '/update', name: "productUpdateView", component: productUpdateView, props: true },
			{
				path: '/', name: "productListView", component: productListView, props: true, meta: {
					keepAlive: true, //此组件不需要被缓存
				}
			}
		]



		const router = new VueRouter({
			routes: routes // (缩写) 相当于 routes: routes
		})

		var store = new Vuex.Store({
			state: {
				count: 0,
				shopOptions: [],
				productCatalogOptions: [],
				productGroupOptions: [],
			},
			mutations: {
				increment: function (state) {
					state.count++
				},
				updateShopOptions: function (state, obj) {
					state.shopOptions = obj;
				},
				updateProductCatalogOptions: function (state, obj) {
					state.productCatalogOptions = obj;
				},
				updateProductGroupOptions: function (state, obj) {
					state.productGroupOptions = obj;
				},

			}
		})

		appConfig.router = router;

		appConfig.store = store;
		appConfig.methods = config.methods;
		appConfig.mounted = function () {
			this.loadShopOptions();
			this.loadProductCatalogOptions();
			this.loadProductGroupOptions();
		}
		var vm = new Vue(appConfig);

	</script>

</body>

</html>